//
//  ExamineTitleView.m
//  gdemm
//
//  Created by 乔明超 on 16/10/31.
//  Copyright © 2016年 Goldencis. All rights reserved.
//

#import "ExamineTitleView.h"
#import "ExamineManager.h"
#import "Masonry.h"
@interface ExamineTitleView()
@property(nonatomic,strong)UIImageView * iconImg;
@property(nonatomic,strong)UILabel * titleLabel;
@property(nonatomic,strong)UIImageView *stateImg;
@property(nonatomic,strong)NSTimer *timer;
@end
@implementation ExamineTitleView


-(instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        self.iconImg = [[UIImageView alloc]init];
        self.iconImg.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:self.iconImg];
        
        self.titleLabel = [[UILabel alloc]init];
        self.titleLabel.textColor = [Utils UIColorFromHex:0Xffffff];
        self.titleLabel.font = [UIFont systemFontOfSize:18];
        [self addSubview:self.titleLabel];
        
        self.stateImg = [[UIImageView alloc]init];
        [self.stateImg sizeToFit];
        [self addSubview:self.stateImg];
    }
    return self;
}
- (void)setTitle:(NSString *)title{

    _title = title;
    if ([title isEqualToString:EXAMINE_ROOT_STATUS_TAG]) {
        self.iconImg.image = [Utils getImageByDevce:@"checkBreakOut"];
        self.titleLabel.text = title;
        
    }else if ([title isEqualToString:EXAMINE_CONFIG_STATUS_TAG]){
        self.iconImg.image = [Utils getImageByDevce:@"checkMobileConfig"];
        self.titleLabel.text = title;
        
    }else if ([title isEqualToString:EXAMINE_WLAN_STATUS_TAG]){
        self.iconImg.image = [Utils getImageByDevce:@"checkWlan"];
        self.titleLabel.text = title;
    
    }else if ([title isEqualToString:EXAMINE_PACKAGE_STATUS_TAG]){
        self.iconImg.image = [Utils getImageByDevce:@"checkPackages"];
        self.titleLabel.text = title;
    }
    
    NSDictionary *examineDict = [ExamineManager getInstance].examineResult;
    if (examineDict[title] == nil) {
        self.stateImg.image = [Utils getImageByDevce:@"ceping_icon_07"];
        
    }else{
        [self.timer invalidate];
        
        if ([examineDict[title] boolValue] == YES) {
            
            self.stateImg.image = [Utils getImageByDevce:@"ceping_icon_10"];
            
        }else{
        
            self.stateImg.image = [Utils getImageByDevce:@"ceping_icon_07"];
        }
        
    }
        
}


-(void)layoutSubviews{
    if ([DeviceTypeJudge isPadDeviceType]) {
        [self.iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.mas_left).mas_offset(30);
            make.top.mas_equalTo(self).mas_offset(30);
            make.width.height.mas_equalTo(18);
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.iconImg.mas_right).mas_offset(25);
            make.top.mas_equalTo(self.iconImg);
        }];
        [self.stateImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.iconImg);
            //make.width.height.mas_equalTo(22);
            make.right.mas_equalTo(self.mas_right).mas_offset(-30);
        }];
         self.titleLabel.font = [UIFont systemFontOfSize:18];
    }else{
        [self.iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.mas_left).mas_offset(14);
            make.top.mas_equalTo(self).mas_offset(23);
            make.width.height.mas_equalTo(14);
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.iconImg.mas_right).mas_offset(12);
            make.top.mas_equalTo(self.iconImg);
        }];
        [self.stateImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.iconImg);
            make.width.height.mas_equalTo(14);
            make.right.mas_equalTo(self.mas_right).mas_offset(-15);
        }];
         self.titleLabel.font = [UIFont systemFontOfSize:14];
    }
  
    
    [super layoutSubviews];
}


-(void)transformAction:(NSTimer *)timer {
    self.stateImg.transform =  CGAffineTransformRotate(self.stateImg.transform, M_PI*0.05);
    
    HRLog(@"M++++++++++++++++++M %@",[timer userInfo]);
 
}
- (void)dealloc{
    [self.timer invalidate];
}
@end
